package com.rankeiot.platform.controller;

import com.rankeiot.core.anno.Auth;
import com.rankeiot.core.data.response.PageResp;
import com.rankeiot.core.data.response.Resp;
import com.rankeiot.core.inner.argumet.QueryPage;
import com.rankeiot.core.sqltoy.Sql;
import com.rankeiot.platform.PlatformMenu;
import com.rankeiot.platform.domain.SlowSqlLog;
import lombok.RequiredArgsConstructor;
import org.sagacity.sqltoy.dao.SqlToyLazyDao;
import org.sagacity.sqltoy.model.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Auth(PlatformMenu.SLOWSQL_LOG)
@RestController
@RequestMapping("overtimesql")
@RequiredArgsConstructor
public class OverTimeSqlController {
    //    @Inject
//    AutoBox auto;
    final SqlToyLazyDao dao;

    @PostMapping("list")
    public PageResp<SlowSqlLog> list(QueryPage query) {

        Sql sql = Sql.select("*")
                .from(SlowSqlLog.TABLE)
                .orderByDesc(SlowSqlLog::getLogTime);

       Page<SlowSqlLog> page = dao.findPageBySql(query.page(), sql.toString(), new SlowSqlLog());

        return Resp.of(page);
    }
}
